template <typename type>
inline TVector3<type>::TVector3() : X(0), Y(0), Z(0)
{
}

template <typename type>
inline TVector3<type>::TVector3(type i)
{
    X = i;
    Y = i;
    Z = i;
}

template <typename type>
inline TVector3<type>::TVector3(type x, type y, type z)
{
    X = x;
    Y = y;
    Z = z;
}

template <typename type>
inline TVector3<type>::TVector3(const TVector3<type> &v)
{
    X = v.X;
    Y = v.Y;
    Z = v.Z;
}

template <typename type>
inline TVector3<type>::TVector3(const TVector3<type> &from, const TVector3<type> &to)
{
    X = to.X - from.X;
    Y = to.Y - from.Y;
    Z = to.Z - from.Z;
}

template <typename type>
inline TVector3<type> &TVector3<type>::operator= (const TVector3<type> &v)
{
    X = v.X;
    Y = v.Y;
    Z = v.Z;
    return *this;
}

template <typename type>
inline TVector3<type> &TVector3<type>::operator+= (const TVector3<type> &v)
{
    X += v.X;
    Y += v.Y;
    Z += v.Z;
    return *this;
}

template <typename type>
inline TVector3<type> TVector3<type>::operator+ (const TVector3<type> &v) const
{
    TVector3 t = *this;
    t += v;
    return t;
}

template <typename type>
inline TVector3<type> &TVector3<type>::operator-= (const TVector3<type> &v)
{
    X -= v.X;
    Y -= v.Y;
    Z -= v.Z;
    return *this;
}

template <typename type>
inline TVector3<type> TVector3<type>::operator- (const TVector3<type> &v) const
{
    TVector3 t = *this;
    t -= v;
    return t;
}

template <typename type>
inline TVector3<type> &TVector3<type>::operator*= (const type a)
{
    X *= a;
    Y *= a;
    Z *= a;
    return *this;
}

template <typename type>
inline TVector3<type> TVector3<type>::operator* (const type a)const
{
    TVector3 t = *this;
    t *= a;
    return t;
}

template <typename type>
inline TVector3<type> &TVector3<type>::operator/= (const type a)
{
    X /= a;
    Y /= a;
    Z /= a;
    return *this;
}

template <typename type>
inline TVector3<type> TVector3<type>::operator/ (const type a)const
{
    TVector3 t = *this;
    t /= a;
    return t;
}

template <typename type>
inline TVector3<type> TVector3<type>::crossProduct(const TVector3<type> &v)const
{
    TVector3 t;
    t.X = Y*v.Z - Z*v.Y;
    t.Y = Z*v.X - X*v.Z;
    t.Z = X*v.Y - Y*v.X;
    return t;
}

template <typename type>
inline type TVector3<type>::length()const
{
    return sqrt(X*X + Y*Y + Z*Z);
}

template <typename type>
inline TVector3<type> &TVector3<type>::normalize()
{
    if(length() == 0)
        return (*this);
    else
    {
        (*this) /= length();
        return (*this);
    }
}
